package com.demo.springBoot2.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.demo.springBoot2.entity.ChatMessages;
import com.demo.springBoot2.entity.UsersInfo;
import com.demo.springBoot2.entity.dto.ChatMessagesDTO;
import com.demo.springBoot2.mapper.ChatMessagesMapper;
import com.demo.springBoot2.mapper.UsersInfoMapper;
import com.demo.springBoot2.service.IChatMessagesService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 聊天消息 服务实现类
 * </p>
 *
 * @author wuHua·pl
 * @since 2024-03-27
 */
@Service
public class ChatMessagesServiceImpl extends ServiceImpl<ChatMessagesMapper, ChatMessages> implements IChatMessagesService {
    @Autowired
    private UsersInfoMapper usersInfoMapper;

    @Override
    public List<ChatMessagesDTO> getContent(ChatMessages chatMessages) {
        List<ChatMessagesDTO> chatMessagesDTOList = new ArrayList<ChatMessagesDTO>();
        ChatMessagesDTO chatMessagesDTO = new ChatMessagesDTO();
        List<ChatMessages> chatMessagesList = getBaseMapper().selectContent(chatMessages);
        for (ChatMessages chatMessages1 : chatMessagesList) {
            BeanUtil.copyProperties(chatMessages1, chatMessagesDTO);
            UsersInfo usersInfo = usersInfoMapper.selectUserByUserId(chatMessages1.getUserId());
            chatMessagesDTO.setUserId(usersInfo.getUserId());
            chatMessagesDTO.setNickname(usersInfo.getNickname());
            chatMessagesDTOList.add(chatMessagesDTO);
            chatMessagesDTO = new ChatMessagesDTO();
            System.err.println(chatMessagesDTOList);
        }
        return chatMessagesDTOList;
    }
}
